import axios from 'axios'
 
// 配置项
const axiosOption = {
  baseURL: 'http://localhost:1337',
  timeout: 5000
}
 
const instance = axios.create(axiosOption);
 
// 添加请求拦截器
instance.interceptors.request.use(config => {
//   let token = localStorage.getItem('token')
//   if(token){
//     config.headers = {
//       'token': token
//     }
//   }
  // config.headers = {
  //   // 'X-Requested-With': 'XMLHttpRequest',
  //   "Accept": "application/json",
  //   'Content-Type': 'application/json'
  // }
  return config;
}, error => {
  return Promise.reject(error);
});
 
// 添加响应拦截器
instance.interceptors.response.use(response =>{
  // console.log('response',response)
  if(response.status == 200){
    return response.data
  }else{
    return Promise.reject('网络错误，请稍后重试。。。')
  }
}, error => {
  console.log('error',error)
  return Promise.reject(new Error(error.message))
});
 
export default instance;